import config from "./config"

export default function request(url , data , method="GET"){
  return new Promise((resolve,reject) => {
    wx.request({
      url: config.localhost + url,
      data,
      header:{
        cookie:wx.getStorageSync('cookie') && wx.getStorageSync('cookie').join(';'),
      },
      method,
      success:(res) => {
        if(data.isLogin){
          wx.setStorageSync('cookie', res.cookies)
        }

        resolve(res.data)
      },
      fail:() => {
        reject(err)
      }
    })
  })
}